***Author: Clemens Noelke

noi di in yellow "EHTrtVars: " in green _col(20) "syntax, " in yellow "  Creates treatment variables for event history models."

cap program drop EHTrtVars
program define EHTrtVars, rclass
syntax, PREFIX(string) TRTVAR(string) OMIT(string) TIMEVAR(string)

qui tab `timevar', gen(___d)
forval vl = 1/`r(r)' {
	local lbl : variable label ___d`vl'
	local lbl = real(subinstr("`lbl'","`timevar'== ","",.))
	local lbl = string(`lbl')
	local lbl = subinstr("`lbl'","-","m",.)
	if "`lbl'"!="`omit'" {	
		qui gen `prefix'`lbl'=___d`vl'*`trtvar'
		local trtvars "`trtvars' `trtvar'_`lbl'"
	}
	macro drop _lbl
}
drop ___d*

return local trtvars "`trtvars'"

end

exit
